package com.yoyo.itravel.dao;

import com.yoyo.itravel.bean.TravelerInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * 常用旅客持久层接口
 * @author wanpeng
 * @version v1.0
 * @date 2020/6/17 14:33
 */
@Repository
public interface ITravelerInfoDao {

    /**
     * 通过用户id查看常用旅客信息
     * @return
     */
    @Select("SELECT * FROM tb_traveler_info WHERE travelerId =(SELECT travelerId FROM middle_tb_user_travelerinfo WHERE userId = #{userId})")
    List<TravelerInfo> showAllTravelerInfo(String userId) throws SQLException;

    /**
     * 添加常用旅客信息
     * @param travelerInfo
     */
    @Insert("insert into tb_traveler_info(travelerId,realName,phone,IDCard) values(#{travelerId},#{realName},#{phone},#{IDCard})")
    int addTraveler(TravelerInfo travelerInfo) throws SQLException;

    /**
     * 根据常用旅客id修改对应旅客信息
     * @param travelerInfo
     */
    @Update("update tb_traveler_info set realName=#{travelerInfo.realName},phone=#{travelerInfo.phone} ,IDCard=#{travelerInfo.IDCard}  where travelerId=#{travelerInfo.travelerId}")
    int updateTraveler( @Param("travelerInfo") TravelerInfo travelerInfo ) throws SQLException;


    /**
     * 根据常用旅客id删除对应旅客信息
     * @param travelerId
     */
    @Delete("delete from tb_traveler_info where travelerId=#{travelerId}")
    int deleteTraveler(String travelerId)throws SQLException;

}
